<?php
	if (isset($_POST['phoneNumber'], $_POST['txt']))
	{
		session_start();
		//$txt=nl2br(htmlentities($_POST['txt'],ENT_QUOTES,'UTF-8'));
		//$phoneNumber=nl2br(htmlentities($_POST['$phoneNumber'],ENT_QUOTES,'UTF-8'));
		
		$txt = htmlentities($_POST['txt'],ENT_QUOTES,'UTF-8');
		$phoneNumber = htmlentities($_POST['phoneNumber'],ENT_QUOTES,'UTF-8');

		include_once 'Util/includeAll.php';
		
		if(!isConnected())
		{
			echo "Vous n'est pas connecté!";
		}
		else
		{
			//on récupère l'user
			$u = getUser();
			//TODO test
			$phone_ID = 1;
			
			$rq = "INSERT INTO message (id_user, id_phone, dest_number, txt, dh, accuse, isExpediteur) 
			VALUES ($u->id, $phone_ID, '$phoneNumber', '$txt', NOW(), 0,1)";
			
			$retour = executeBDD($rq);
			
			if($retour != null)
			{
				echo "OK";
			}
			else
			{
				echo "Une erreur s'est produite :(";
			}
		}
	}
	else
	{
		echo "Params manquants !";
	}
?>